package com.tgy.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.tgy.admin.Service.FriendLinkService;
import com.tgy.bo.FriendLinkBO;
import com.tgy.bo.QueryFriendLinkBO;
import com.tgy.mo.FriendLinkMO;
import com.tgy.result.GraceJSONResult;
import com.tgy.result.LayuiTableResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Validated
@Api(value = "友情链接", tags = {"友情链接管理"})
@RestController
@RequestMapping("/admin/friendLink")
public class AdminFriendLinkController {

    @Resource
    private FriendLinkService friendLinkService;

    /**
     * 根据逻辑删除状态获取友情链接
     */
    @GetMapping("/getAllFriendLinkByIsDelete")
    @ApiOperation("根据逻辑删除状态获取友情链接")
    @SaCheckPermission("friendLink:query")
    public GraceJSONResult getAllFriendLinkByIsDelete(Integer isDelete) {
        List<FriendLinkMO> linkMOS = friendLinkService.getAllFriendLinkByIsDelete(isDelete);
        return GraceJSONResult.ok(linkMOS);
    }

    /**
     * 根据ID获取友情链接
     */
    @GetMapping("/getAllFriendLinkById")
    @ApiOperation("根据ID获取友情链接")
    @SaCheckPermission("friendLink:query")
    public GraceJSONResult getAllFriendLinkById(String id) {
        FriendLinkMO linkMOS = friendLinkService.getAllFriendLinkById(id);
        return GraceJSONResult.ok(linkMOS);
    }

    /**
     * 分页查询友情链接
     */
    @GetMapping("/getAllFriendLink")
    @ApiOperation("分页查询友情链接")
    @SaCheckPermission("friendLink:query")
    public LayuiTableResult getAllFriendLink(QueryFriendLinkBO queryFriendLinkBO) {
        return friendLinkService.getAllFriendLink(queryFriendLinkBO);
    }

    /**
     * 新增或修改友情链接
     */
    @PostMapping("/saveOrUpdateFriendLink")
    @ApiOperation("新增或修改友情链接")
    // SaMode.OR  和  SaMode.AND
    @SaCheckPermission(value = {"friendLink:add", "friendLink:update", "user-delete"}, mode = SaMode.OR)
    public GraceJSONResult saveOrUpdateFriendLink(@Valid FriendLinkBO friendLinkBO) {
        friendLinkService.saveOrUpdateFriendLink(friendLinkBO);
        return GraceJSONResult.ok();
    }

    /**
     * 删除友情链接
     */
    @GetMapping("/delete")
    @ApiOperation("删除友情链接")
    @SaCheckPermission("friendLink:del")
    public GraceJSONResult delete(String linkId) {
        friendLinkService.delete(linkId);
        return GraceJSONResult.ok();
    }


}
